
use std::fs::File;
use std::io::{self, Read};
use std::num;

#[derive(Debug)]
struct AppErr {
    kind: String,
    msg: String,
}

impl From<io::Error> for AppErr {
    fn from(e: io::Error) -> Self {
        AppErr {
            kind: String::from("io"),
            msg: e.to_string(),
        }
    }
}

impl From<num::ParseIntError> for AppErr {
    fn from(e: num::ParseIntError) -> Self {
        AppErr {
            kind: String::from("parse"),
            msg: e.to_string(),
        }
    }
}

// fn main() -> Result<(), AppErr> {
//     // println!("Hello, world!");
//     let _file = File::open("none-exists-file.txt")?;
//     Ok(())
// }

fn main() -> Result<(), AppErr> {
    let mut file = File::open("hello_world.txt")?;
    let mut content = String::new();
    file.read_to_string(&mut content)?;

    let _num: usize;
    _num = content.parse()?;

    Ok(())
}